package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.entity.Works;
import com.example.mapper.WorksMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 功能：作品服务层
 * 日期：2024/1/28 19:56
 */
@Service
public class WorksService {

    @Resource
    private WorksMapper worksMapper;


    public void add(Works works) {
        works.setDate(DateUtil.today());
        worksMapper.insert(works);
    }

    public void updateById(Works works) {
        worksMapper.updateById(works);
    }

    public void deleteById(Integer id) {
        worksMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            worksMapper.deleteById(id);
        }
    }

    public Works selectById(Integer id) {
        Works works = worksMapper.selectById(id);
        return works;
    }

    public List<Works> selectAll(Works works) {
        return worksMapper.selectAll(works);
    }

    public PageInfo<Works> selectPage(Works works, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Works> worksList = worksMapper.selectAll(works);
        return PageInfo.of(worksList);
    }

    public PageInfo<Works> selectHotWorks(Works works, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Works> worksList = worksMapper.selectHotWorks(works);
        return PageInfo.of(worksList);
    }
}